<template>
  <div>
    <el-form
      ref="searchForm"
      class="searchForm"
      :model="searchForm.queryCondition"
      label-width="50"
    >
      <el-row :gutter="12">
        <!--        合计24份  -->
        <el-col :span="6">
          <el-form-item prop="applierSml">
            <el-input
              v-model.trim="searchForm.queryCondition.applierSml"
              placeholder="申请人..."
            >
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="leaveTypes">
            <el-select
              multiple
              v-model="searchForm.queryCondition.leaveTypes"
              placeholder="请假类型..."
            >
              <el-option
                v-for="e in leaveTypeEnums"
                :key="e.value"
                :value="e.value"
                :label="e.text"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="auditStates">
            <el-select
              multiple
              v-model="searchForm.queryCondition.auditStates"
              placeholder="审核状态..."
            >
              <el-option
                v-for="e in auditStateEnums"
                :key="e.value"
                :value="e.value"
                :label="e.text"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-edit"
          @click="queryByCondition(1)"
          >查询</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-remove"
          @click="() => $refs.searchForm.resetFields()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!--    {
      "leaveId": 16,
      "applier": "libai06",
      "applyTime": "2021-10-29T10:27:34.878",
      "auditor": null,
      "auditTime": null,
      "applyState": "submitted",
      "auditState": "notAudit",
      "deleted": false,
      "version": 1,
      "startTime": "2021-10-13T16:00:00",
      "endTime": "2021-10-21T16:00:00",
      "reason": "c而是搬家请假，工作愉快",
      "auditWord": null,
      "leaveType": "annualLeave"
    },     -->
    <el-table :data="results" class="resultsTable" stripe>
      <el-table-column prop="leaveId" label="ID/Code"></el-table-column>
      <el-table-column prop="applier" label="申请人"></el-table-column>
      <el-table-column
        label="请假类型"
        :formatter="leaveTypeFormat"
      ></el-table-column>
      <el-table-column
        label="请假原因"
        :formatter="({ reason }) => format.thumbnail(reason)"
      ></el-table-column>
      <!--              <el-table-column label="" :formatter="Format" align="center">-->
      <!--              </el-table-column>-->
      <el-table-column
        label="审核状态"
        :formatter="auditStateFormat"
      ></el-table-column>
      <el-table-column
        label="审核批语"
        :formatter="({ auditWord }) => format.thumbnail(auditWord)"
      ></el-table-column>
      <el-table-column width="180px" fixed="left">
        <template slot-scope="props">
          <el-button
            class="el-button--mini"
            type="warning"
            icon="el-icon-edit"
            @click="()=>$refs.auditSF.appear(props.row.leaveId)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :page-size="searchForm.pageSize"
      :current-page="searchForm.pageNum"
      @current-change="queryByCondition"
      layout="total, prev, pager, next, jumper"
    ></el-pagination>
    <audit-s-f ref="auditSF" @postSubmit="queryByCondition"></audit-s-f>
  </div>
</template>

<script>
// import New from './components/New.vue';
import format from "@/utils/format";
import AuditSF from "@/components/hr/AuditSF";
export default {
  name: "LeaveAudit",
  components: {
    AuditSF
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      format,
      searchForm: {
        pageNum: 1,
        pageSize: 6,
        queryCondition: {
          applierSml: "",
          auditStates: [],
          leaveTypes: [],
        },
      },
      total: 7,
      /**
       *   {
      "leaveId": 16,
      "applier": "libai06",
      "applyTime": "2021-10-29T10:27:34.878",
      "auditor": null,
      "auditTime": null,
      "applyState": "submitted",
      "auditState": "notAudit",
      "deleted": false,
      "version": 1,
      "startTime": "2021-10-13T16:00:00",
      "endTime": "2021-10-21T16:00:00",
      "reason": "c而是搬家请假，工作愉快",
      "auditWord": null,
      "leaveType": "annualLeave"
    },    
       * */
      results: [],
    };
  },
  computed: {
    // sampleC() {
    //     return this.sampleD+'--';
    // }
    leaveTypeEnums() {
      return this.$store.state.leaveTypeEnums;
    },
    applyStateEnums() {
      return this.$store.state.applyStateEnums;
    },
    auditStateEnums() {
      return this.$store.state.auditStateEnums;
    },
  },
  created() {},
  mounted() {
    this.queryByCondition(1);
  },
  methods: {
    sampleM() {},
    queryByCondition(pageNum) {
      if (pageNum) this.searchForm.pageNum = pageNum;
      this.$http({
        method: "post",
        url: "http://localhost:9091/leave/leaveBill/query/audit",
        data: this.searchForm,
      }).then(
        (res) => {
          this.total = res.data.total;
          this.results = res.data.results;
        },
        (error) => {
          this.$message.warning("query mistake：" + error.response.status);
        }
      );
    },
    leaveTypeFormat(row) {
      let f = this.leaveTypeEnums.find((x) => x.value === row.leaveType);
      return f ? f.text : "N/A";
    },
    applyStateFormat(row) {
      let f = this.applyStateEnums.find((x) => x.value === row.applyState);
      return f ? f.text : "N/A";
    },
    auditStateFormat(row) {
      let f = this.auditStateEnums.find((x) => x.value === row.auditState);
      return f ? f.text : "N/A";
    },
    // reasonFormat(row){
    //   return format.thumbnail(row.reason)
    // }
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
